// integral.js
//index.js  
//获取应用实例  
var app = getApp()
Page({
  data: {
    /** 
        * 页面配置 
        */
    winWidth: 0,
    winHeight: 0,
    // tab切换  
    currentTab: '0',
    status: 1,
    p: 1,
    list:[]
  },
  onLoad: function (options) {
    var that = this;
    options = options
    if (options.currentTab) {
      that.setData({
        currentTab: 1,
        status: 0,
      });
    }

    /** 
     * 获取系统信息 
     */
    wx.getSystemInfo({

      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight
        });
      }

    });
  },
  onShow: function () {
    this.getlist();
  },
  /** 
 * 滑动切换tab 
 */
  bindChange: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current,
      // status: e.detail.current
    });
    // console.log(e.detail.current)
  },
  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {
    var that = this;
    if (that.data.status != e.target.dataset.status) {
      that.setData({
        status: e.target.dataset.status,
        list: [],
        p:1
      })
      that.getlist();
    }
    if (that.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({        
        currentTab: e.target.dataset.current,        
      })      
    }    
  },
  chooseicon: function (e) {
    var strnumber = e.target.dataset.id;
    var _obj = {};
    _obj.curHdIndex = strnumber;
    this.setData({
      tabArr: _obj
    });
  },
  getlist: function () {
    var app = getApp()
    var that = this;
    var uid = wx.getStorageSync('uid');
    var status = that.data.status
    console.log(that.data.status)
    // console.log(uid)
    wx.request({
      url: app.globalData.host + '&g=App&m=User&a=my_og',
      data: {
        uid: uid,
        status: that.data.status,
        p: that.data.p,
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.status == 1) {
          var list = that.data.list
         console.log(res.data)
         // console.log(res.data.list.length)
         var ol = list.length
          for (var i = 0; i < res.data.page.dataNow; i++){
            list[ol + i] = res.data.list[i];
          }
          console.log(res.data)
          var ad = res.data.ad;
          that.setData({
            p: that.data.p + 1,
            list: list,
          })
        }
      }
    })
    that.setData({
      isHide: 1,
    })
    wx.hideNavigationBarLoading()
  },
  onReachBottom: function () {
    console.log('--------下拉刷新-------')
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.getlist();
  },
}) 
